package com.example.song.wlms.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.song.wlms.bean.ReconmmendData;

import java.util.List;

/**
 * Created by song on 2017/2/9.
 */

public class RecommendbannerAdapter extends PagerAdapter {
    private List<ReconmmendData.DataBean.BANNERBean> list;
    private Context context;

    public RecommendbannerAdapter(List<ReconmmendData.DataBean.BANNERBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list != null ? list.size() : 0;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View ret = null;
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        Glide.with(context).load(list.get(position).getImg()).into(imageView);
        ret = imageView;
        container.addView(ret);
        return ret;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        if (object instanceof View) {
            View view = (View) object;
            container.removeView(view);
        }
    }
}
